<?php

namespace FactoryFunction;


class Client
{
    public static function main()
    {
        // create product A
        $product_a = FactoryProductA::create();
        $product_a->display();

        // create product B
        $product_b = FactoryProductB::create();
        $product_b->display();
    }
}

/**
 * 由具体产品工厂类决定生产何种产品
 * Interface Factory
 * @package FactoryFunction
 */
interface Factory
{
    public static function create(): Product;
}

class FactoryProductA implements Factory
{

    public static function create(): Product
    {
        return new ProductA();
    }
}

class FactoryProductB implements Factory
{

    public static function create(): Product
    {
        return new ProductB();
    }
}



interface Product
{
    public function display(): void;
}

class ProductA implements Product
{

    public function display(): void
    {
        echo 'product A description.', PHP_EOL;
    }
}

class ProductB implements Product
{

    public function display(): void
    {
        echo 'product B description.', PHP_EOL;
    }
}


Client::main();
